package com.bizfx.component.controls
{
	import com.bizfx.events.ListItemSelectorHeaderClickEvent;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.controls.CheckBox;
	import mx.controls.DataGrid;
	import mx.events.DataGridEvent;
	
	final public class ListItemSelectorHeaderRenderer extends CheckBox
	{
		
		public function ListItemSelectorHeaderRenderer() {
			super();
		}
		
		private var _data:ListItemSelectorColumn;
		
		override public function get data():Object {
			return _data;
		}
		
		override public function set data(value:Object):void {
			_data = value as ListItemSelectorColumn;
			DataGrid(listData.owner).addEventListener(DataGridEvent.HEADER_RELEASE, sortEventHandler);
			selected = _data.selected;
		}
		
		private function sortEventHandler(event:DataGridEvent):void {
			if (event.itemRenderer == this)
				event.preventDefault();
		}
		
		override protected function clickHandler(event:MouseEvent):void {
			super.clickHandler(event);
			
			data.selected = selected;
			data.dispatchEvent(new ListItemSelectorHeaderClickEvent(data.selected));
		}
	}
}